<?php
namespace Plu\qdh\Models\App;

use Phalcon\Mvc\Model;

class Product extends Model
{

    // CREATE TABLE `product` (
    //     `id` int(11) NOT NULL AUTO_INCREMENT,
    //     `productNo` int(11) NOT NULL COMMENT '第三方产品号',
    //     `is_confirm` tinyint(1) NOT NULL,
    //     `productName` varchar(45) NOT NULL,
    //     `salePrice` decimal(8,2) NOT NULL,
    //     `SettlementPrice` decimal(8,2) NOT NULL COMMENT '结算价',
    //     `price` decimal(8,2) NOT NULL COMMENT '自定义售价',
    //     `productcol` varchar(45) DEFAULT NULL,
    //     `payCount` int(64) DEFAULT NULL COMMENT '当前付款数量',
    //     `refoundCount` int(64) DEFAULT NULL COMMENT '当前退款数量',
    //     `createTime` datetime DEFAULT NULL,
    //     `updateTime` datetime DEFAULT NULL,
    //     PRIMARY KEY (`id`)
    //   ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    public function initialize() {
        $this->setConnectionService('db.qdh');
        $this->allowEmptyStringValues([]);
    }

	public function getSource() {
		return "product";
    }

    static public function getCount() {
        return self::count();
    }

    static public function getItemByProductNo($productNo) {
        $item = self::findFirst([
            'conditions' => 'productNo = :productNo:',
            'bind' => [
                'productNo' => $productNo
            ]
        ]);
        return $item;
    }
    
    static public function getItemById($Id) {
        $item = self::findFirst([
            'conditions' => 'id = :id:',
            'bind' => [
                'id' => $Id
            ]
        ]);
        return $item;
    }

    static public function getItems($limit, $offset) {
        $count = self::count();
        $items = self::find([
            'limit'  => $limit,
            'offset' => $offset
        ]);
        if ($items) {
            $items = $items->toArray();
            return [$count, $items];
        }
        return [0, []];
    }





}